package com.yangsen.index;

import com.jfinal.render.FileRender;

import java.io.File;

/*
* 代码来源 http://www.codeweblog.com/jfinal-%E4%B8%B4%E6%97%B6%E6%96%87%E4%BB%B6%E4%B8%8B%E8%BD%BD-%E7%94%A8%E6%88%B7%E4%B8%8B%E8%BD%BD%E5%AE%8C%E6%88%90%E5%90%8E%E5%88%A0%E9%99%A4%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%9A%84%E6%96%87%E4%BB%B6/
* */

public class TempFileRender extends FileRender {
    private String fileName;
    private File file;

    public TempFileRender(String fileName) {
        super(fileName);
        this.fileName = fileName;
    }

    public TempFileRender(File file) {
        super(file);
        this.file = file;
    }

    @Override
    public void render() {
        try {
            super.render();
        } finally {

            if (null != fileName) {
                file = new File(fileName);
            }

            if (null != file) {
                file.delete();
                file.deleteOnExit();
            }
        }
    }
}
